package com.hmdp.utils;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.hmdp.dto.UserDTO;
import com.hmdp.entity.User;
import lombok.val;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @className: com.hmdp.utils-> Logintnerceptor
 * @description: 这个类是做做什么得吖，小朋友？
 * @author: chenhs
 * @createDate: 2024-03-02 22:42
 * @version: 1.0
 */
public class LoginInterceptor implements HandlerInterceptor {


    /*前置拦截*/
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//  判断用户是否存在
        if (UserHolder.getUser() == null) {
            response.setStatus(401);
            return false;
        }
        return HandlerInterceptor.super.preHandle(request, response, handler);
    }

}
